package com.tzjw.servlet;

import com.tzjw.bean.MarketStorage;
import com.tzjw.bean.common.BaseRespVo;
import com.tzjw.service.AdminStorageService;
import com.tzjw.service.AdminStorageServiceImpl;
import lombok.SneakyThrows;

import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

@MultipartConfig
@WebServlet("/admin/storage/*")
public class AdminStorageServlet extends WdBaseServlet {

    AdminStorageService adminStorageService = new AdminStorageServiceImpl();

    @SneakyThrows
    public BaseRespVo create(HttpServletRequest request, HttpServletResponse response) {
        String storagePath = (String) getServletContext().getAttribute("storagePath");
        Part part = request.getPart("file");

        MarketStorage marketStorage = adminStorageService.saveAndCreateRecord(storagePath, part);
        return BaseRespVo.ok(marketStorage);
    }


}
